#include "renderFireFloor.h"
#define SCALE 4
#define HEIGHT 4

renderFireFloor::renderFireFloor(float init_red, float init_green, float init_blue)
{
	// Initialize the variables then load the texture!
	r = init_red; g = init_green; b = init_blue;
	loadOpenGL2DTextureBMP("floor.bmp", &floor_texture, GL_RGB);
}

renderFireFloor::~renderFireFloor(void)
{
}

void renderFireFloor::draw(float init_x, float init_y, float init_z)
{

	static double fire_rotation = 0;
	x = (init_x * SCALE);
	y = (init_y * SCALE);
	z = (init_z * SCALE);
	int z_fire = ((init_z + .5) * SCALE);

	GLfloat nothing[] = {0,0,0,0};
	GLfloat mat_ambient[] = { 1, 1, 1, 1};
	GLfloat mat_diffuse[] = { 1, 1, 1, 1 };
	GLfloat mat_specular[] = { 1, 1, 1, 1 };
	GLfloat mat_emission []= { 0.0 , 0.0 , 0.0 , 0.0 } ;

	glPushMatrix();

	//	/* Set up material properties. */
	glEnable(GL_TEXTURE_2D);
	glTranslatef(x, y, z);
	glColor3f(r, g, b); 
	glScalef(1.0, 1.0, 0.2);
	glBindTexture(GL_TEXTURE_2D, floor_texture); 	
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, mat_emission);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0 ); /* No effect if specular == 0 */
	//glutSolidCube(SCALE);

	//START THE QUADS!
	glBegin(GL_QUADS);

	glNormal3f(0,0,-1);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, 0.0, 0.0);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, 0.0);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE, 0.0);

	glNormal3f(0,0,1);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, SCALE);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE, SCALE);

	glNormal3f(-1,0,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 0.0, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, 0.0, 0.0);

	glNormal3f(1,0,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, SCALE, 0.0);

	glNormal3f(0,-1,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 0.0, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, 0.0, 0.0);

	glNormal3f(0,1,0);
	glTexCoord2f(0.0, 0.0); glVertex3f(SCALE, SCALE, 0.0);
	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, 0.0, 0.0);

	glEnd();

	glTranslatef(-x, -y, -z);
	glDisable(GL_TEXTURE_2D);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(x + (SCALE / 2), y + (SCALE / 2), z_fire);
	glColor3f(1.0000f, 0.3803f, 0.0000f); 
	glScalef(0.5, 0.5, 0.5);
	glRotatef(fire_rotation, 0.0, 0.0, 1.0);
	glRotatef(fire_rotation, 0.0, 9.0, 1.0);
	glRotatef(fire_rotation, 8.0, 9.0, 1.0);
	glTranslatef(-(SCALE / 4), -(SCALE / 4), 0);


	glBindTexture(GL_TEXTURE_2D, floor_texture); 	
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, nothing);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, nothing);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, nothing);
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, nothing);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0 ); /* No effect if specular == 0 */

	glScalef(SCALE, SCALE, SCALE); 
	glutSolidOctahedron();		
	//glBegin(GL_QUADS);

	//	glNormal3f(0,0,-1);
	//	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
	//	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, 0.0, 0.0);
	//	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, 0.0);
	//	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE, 0.0);

	//	glNormal3f(0,0,1);
	//	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, SCALE);
	//	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	//	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	//	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE, SCALE);

	//	glNormal3f(-1,0,0);
	//	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
	//	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 0.0, SCALE);
	//	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	//	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, 0.0, 0.0);

	//	glNormal3f(1,0,0);
	//	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE, 0.0);
	//	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE, SCALE);
	//	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	//	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, SCALE, 0.0);

	//	glNormal3f(0,-1,0);
	//	glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE, 0.0);
	//	glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE, SCALE);
	//	glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 0.0, SCALE);
	//	glTexCoord2f(1.0, 0.0); glVertex3f(0.0, 0.0, 0.0);

	//	glNormal3f(0,1,0);
	//	glTexCoord2f(0.0, 0.0); glVertex3f(SCALE, SCALE, 0.0);
	//	glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
	//	glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
	//	glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, 0.0, 0.0);

	//glEnd();

	glTranslatef(-x - (SCALE / 4), -y - (SCALE / 4), -z_fire);
	glPopMatrix();

	fire_rotation = fire_rotation + 13;

	glFlush();

}